package com.brayan.melinxa.gui;

import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.UIManager;

import com.brayan.melinxa.gui.panels.DestinationPanel;
import com.brayan.melinxa.gui.panels.SourcePanel;
import com.brayan.melinxa.gui.panels.SummaryPanel;
import com.brayan.melinxa.gui.wizard.Wizard;
import java.awt.Color;

public class MainWindow {

	private JFrame frmMelinxaMirror;
	private Wizard wiz = null;

	public MainWindow() {
		initialize();
		frmMelinxaMirror.setVisible(true);
	}

	private void initialize() {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {

		}

		frmMelinxaMirror = new JFrame();
		frmMelinxaMirror.getContentPane().setBackground(Color.WHITE);
		// TODO Use a relative path.
		URL imgURL = ClassLoader.getSystemResource("media/Suivant-Sky-256.png");
		frmMelinxaMirror.setIconImage(Toolkit.getDefaultToolkit().getImage(imgURL));
		frmMelinxaMirror.setTitle("Melinxa Mirror");
		frmMelinxaMirror.setBounds(100, 100, 450, 300);
		// TODO default close operation must be: minimize
		frmMelinxaMirror.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JMenuBar menuBar = new JMenuBar();
		frmMelinxaMirror.getContentPane().add(menuBar, BorderLayout.NORTH);

		JMenu mnFile = new JMenu("File");
		menuBar.add(mnFile);

		JMenuItem mntmHideWindow = new JMenuItem("Hide window");
		mnFile.add(mntmHideWindow);

		JSeparator separator = new JSeparator();
		mnFile.add(separator);

		JMenuItem mntmExit = new JMenuItem("Exit");
		mnFile.add(mntmExit);

		JMenu mnSettings = new JMenu("Settings");
		menuBar.add(mnSettings);

		JMenuItem mntmSetup = new JMenuItem("Setup Wizard ...");
		mntmSetup.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				List<JPanel> listOfPanels = new ArrayList<JPanel>();
				listOfPanels.add(new SourcePanel());
				listOfPanels.add(new DestinationPanel());
				listOfPanels.add(new SummaryPanel());
				wiz = new Wizard(listOfPanels, frmMelinxaMirror);
				frmMelinxaMirror.getContentPane().add(wiz);
				frmMelinxaMirror.pack();
			}
		});

		JCheckBoxMenuItem chckbxmntmActivateShading = new JCheckBoxMenuItem("Activate Shadowing");
		chckbxmntmActivateShading.setEnabled(false);
		mnSettings.add(chckbxmntmActivateShading);

		JMenuItem mntmMonitorShadingProgress = new JMenuItem("Monitor Shading Progress");
		mnSettings.add(mntmMonitorShadingProgress);

		JSeparator separator_1 = new JSeparator();
		mnSettings.add(separator_1);
		mnSettings.add(mntmSetup);

		JMenuItem mntmInvokeAsA = new JMenuItem("Invoke as a service ...");
		mnSettings.add(mntmInvokeAsA);

		JMenu mnHelp = new JMenu("Help");
		menuBar.add(mnHelp);

		JMenuItem mntmAbout = new JMenuItem("About");
		mntmAbout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				AboutDialog dialog = new AboutDialog();
				dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
				dialog.setVisible(true);
			}
		});
		mnHelp.add(mntmAbout);
	}

}
